package com.yfbao.horizon.schedule.tk.meter;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;

public class MicrometerLogbackAppender extends AppenderBase<ILoggingEvent> {

    private final Counter infoLogCounter = Metrics.counter("logback.logs", "level", "info");
    private final Counter errorLogCounter = Metrics.counter("logback.logs", "level", "error");
    private final Counter warnLogCounter = Metrics.counter("logback.logs", "level", "warn");

    @Override
    protected void append(ILoggingEvent eventObject) {
        switch (eventObject.getLevel().toString()) {
            case "INFO":
                infoLogCounter.increment();
                break;
            case "ERROR":
                errorLogCounter.increment();
                break;
            case "WARN":
                warnLogCounter.increment();
                break;
            default:
                break;
        }
    }
}
